/**
 * dao实现类生成器
 * @author dengzongrong
 * @version 1.1
 * @date 2011-10-09
 */
package com.lemon.ai.socket.packets.spiritgame.model.generator;
import static com.lemon.ai.socket.packets.spiritgame.model.generator.utils.StringUtils.*;
import java.util.List;

import com.lemon.ai.socket.packets.spiritgame.model.db.MetaData;
import com.lemon.ai.socket.packets.spiritgame.model.dto.Table;
import static com.lemon.ai.socket.packets.spiritgame.model.generator.utils.DbUtils.*;
public class DaoImplGenerator extends AbstractGenerator {

	public DaoImplGenerator() {
		super("DaoImplTemp.txt");
	}

	public String generate(Table table) {
		return super.temp.
					replace("PACKAGE_NAME", super.prop.getProperty("package")).
					replace("CLASS_NAME",generateClassName(table.getName())).
					replace("CLASS_PARAMETER",generateParameterName(table.getName())).
					replace("TABLE_NAME", table.getName()).
					replace("COLUMN_NAMES", generateColumnNames(table.getColumns())).
					replace("COLUMN_?S", generateColumn_s(table.getColumns())).
					replace("PK_PARAMETER", generatePkParameters(table)).
					replace("PKCOLUMNS_S", generatePkColumns(table)).
					replace("PK_PS_SETS", generatePkPsSets(table)).
					replace("PS_SETS_ADD", generatePsSets_add(table)).
					replace("PS_SETS_UPDATE", generatePsSets_update(table)).
					replace("PK_COLUMNS", generatePkColumns(table)).
					replace("PAGE_SETS", generatePageSets()).
					replace("RS_GETS", generateRsGets(table)).
					replace("COLUMN_PARAMETERS", generateColumnParameters(table));
	}

	public String generateFileName(Table table) {
		return super.prop.getProperty("dir")
				+ super.prop.getProperty("package").replace(".", "\\")
				+ "\\dao\\Impl\\"
				+ generateClassName(table.getName())
				+ "DAOImpl.java";
	}

	public static void main(String[] args) {
		MetaData meta = MetaData.getInstance();
		List<Table> tables = meta.getTables();
		DaoImplGenerator g = new DaoImplGenerator();
		// g.generate("user");
		Table t = new Table();
		t.setName("user");
		// System.out.println(g.generate(t));
		System.out.println(g.generate(tables.get(0)));
	}

}
